package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author benben278
 * @create 2022-03-11 15:19
 */
@Mapper
public interface CheckItemDao {
    // 检查项目添加进数据库
    @Insert("insert into t_checkitem(code,name,sex,age,price,type,remark,attention) values (#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})")
    void add(CheckItem checkItem);
    //分页和按条件查询
    @Select("<script> select * from t_checkitem <if test=\"value != null and value.length > 0\">\n" +
            "            where code = #{value} or name = #{value}\n" +
            "        </if> </script>")
    Page<CheckItem> selectByCondition(String queryString);
    //根据检查项id统计数据量
    @Select("select count(*) from t_checkgroup_checkitem where checkitem_id=#{checkitem_id}")
    long findCountByCheckItemId(Integer id);
    //根据Id值删除检查项
    @Delete("delete from t_checkitem where id=#{id}")
    void deleteById(Integer id);
    //修改检查项
    @Update("<script>update t_checkitem\n" +
            "        <set>\n" +
            "            <if test=\"name != null\">\n" +
            "                name = #{name},\n" +
            "            </if>\n" +
            "            <if test=\"sex != null\">\n" +
            "                sex = #{sex},\n" +
            "            </if>\n" +
            "            <if test=\"code != null\">\n" +
            "                code = #{code},\n" +
            "            </if>\n" +
            "            <if test=\"age != null\">\n" +
            "                age = #{age},\n" +
            "            </if>\n" +
            "            <if test=\"price != null\">\n" +
            "                price = #{price},\n" +
            "            </if>\n" +
            "            <if test=\"type != null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"attention != null\">\n" +
            "                attention = #{attention},\n" +
            "            </if>\n" +
            "            <if test=\"remark != null\">\n" +
            "                remark = #{remark},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}</script>")
    void edit(CheckItem checkItem);
    //回显数据，id查询
    @Select("select * from t_checkitem where id = #{id}")
    CheckItem findById(Integer id);
    //查询所有检查项数据
    @Select("select * from t_checkitem")
    List<CheckItem> findAll();
}
